package com.company.string;

import java.util.Set;
import java.util.TreeSet;

public class CanPermutePalindrome {

    public boolean canPermutePalindrome(String s) {

        if (s == null || s.length() == 0) return true;
        char[] chars = s.toCharArray();

        Set<Character> set = new TreeSet<>();
        for (int i = 0; i < chars.length; i++) {
            if (set.contains(chars[i])) {
                set.remove(chars[i]);
            } else {
                set.add(chars[i]);
            }
        }
        return set.size() <= 1;
    }

}
